// File:     CircDetec.cpp
//
// Modified: 2011 Jan. 27
//
// 
//

#include "CircleDetection.hpp"
#include "Blob.hpp"
			
CircleDetection::CircleDetection(char* imgName) : blob_ (new Blob(imgName))
// @des:
// @input:
// @output:
{}
			
CircleDetection::~CircleDetection()
// @des:
// @input:
// @output:
{}

void CircleDetection::setHoughCircles(int dp, int minDist, int cannyThresh, int accumulatorThresh, int minRadii, int maxRadii)
// @des:
// @input:
// @output:
{
	this ->storage_ = cvCreateMemStorage(0);	//*** Should we allocate memory per every paths or every CircleDetection object? ***
	this ->results_ = cvHoughCircles(this ->blob_ ->getHue(), this ->storage_, CV_HOUGH_GRADIENT, dp, minDist, cannyThresh, accumulatorThresh, minRadii, maxRadii);

}
			
void CircleDetection::drawCircles()
// @des:
// @input:
// @output:
{
	for( int i = 0; i < this ->results_ ->total; i++ ) 
	{
		float* p = (float*) cvGetSeqElem(this ->results_, i );
		CvPoint pt = cvPoint( cvRound( p[0] ), cvRound( p[1] ) );
		cvCircle(this ->blob_ ->getImg(), pt, cvRound( p[2] ), CV_RGB(0xff,0,0));
	}
}

Blob* CircleDetection::getBlob() const
// @des:
// @input:
// @output:
{
	return this ->blob_;
}